package com.zzzzzz.oms.ordertype;

import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.zzzzzz.core.datagrid.BaseData;
import com.zzzzzz.plugins.shiro.I;
import com.zzzzzz.utils.BeanValidators;
import com.zzzzzz.utils.DateTimeUtils;

@Service
public class OrderTypeService {
	@Resource
	public OrderTypeDao orderTypeDao;
	
	@Resource
	public Validator validator;
	
	// 增加、修改
	@Transactional
	public int save(OrderType orderType, I i) {
		orderType.setUpdDt(new Date());
		orderType.setUpdBy(i.getId());
		if (orderType.getId() == null) {
			orderType.setAddDt(new Date());
			orderType.setAddBy(i.getId());
			orderTypeDao.add(orderType);
		} else {
			orderTypeDao.updById(orderType);
		}

		return 1;
	}
	
	// 通过cd找OrderType，主要是用于其它相关导入作判断。
	public OrderType getOrderTypeByCd(String cd,Long clientId) {
		Map<String, List<OrderType>> allOrderTypeMap = orderTypeDao.getAllOrderTypeMap();
		List<OrderType> orderTypeList = allOrderTypeMap.get(cd);
		if(orderTypeList != null){
			for(OrderType orderType:orderTypeList){
				if(orderType.getClientId().equals(clientId)){
					return orderType;
				}
			}
		}
		return null;
	}

	private static final Logger logger = LoggerFactory.getLogger(OrderType.class);
}
